﻿using ECMS.Domain.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace ECMS.Domain
{
    public class ECMSDbContext : DbContext
    {
        public ECMSDbContext(DbContextOptions<ECMSDbContext> options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            #region Authorities
            modelBuilder.Entity<SysUser>().ToTable("SysUser").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<RouteTemplate>().ToTable("RouteTemplates").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<Menu>().ToTable("Menus").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<Role>().ToTable("Roles").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<RoleGroup>().ToTable("RoleGroups").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<RoleWithRoleGroup>().ToTable("RoleWithRoleGroups").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<SysUserWithRole>().ToTable("SysUserWithRole").Property(p => p.RowVersion).IsRowVersion();

            #endregion
            #region 用户数据
            modelBuilder.Entity<AppUser>().ToTable("AppUser").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<Forum>().ToTable("Forum").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<Reply>().ToTable("Reply").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<Like>().ToTable("Like").Property(p => p.RowVersion).IsRowVersion();
            modelBuilder.Entity<Views>().ToTable("Views").Property(p => p.RowVersion).IsRowVersion();
            #endregion
        }
    }
}
